<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../../css/reset.css" />
		<link rel="stylesheet" type="text/css" href="../../../../common/js/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="../../../../common/js/bootstrap-3.3.7-dist/css/bootstrap-theme.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/store_member/style.css" />

		<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../common/js/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			.container-fluid {
				padding: 0;
			}
			
			input,
			button {
				border: 0;
				outline: none;
			}
			
			.vip_msg_add input {
				padding-left: 0.277777rem;
			}
			
			.container-fluid ul {
				padding-top: 0.277777rem;
				margin-bottom: 2.777777rem;
			}
			
			.container-fluid ul li {
				padding-left: 0.416666rem;
				padding-right: 0.416666rem;
			}
			
			.header {
				box-shadow: 0.069444rem 0.069444rem 0.069444rem #b3b3b3;
			}
		</style>
	</head>

	<body style="background-color: #F5F5F5;">
		<div class="header">
			<a href="javascript:history.go(-1)" class="glyphicon glyphicon-menu-left f28 col-xs-4" style="text-align: left;"></a>
			<span class="f28 col-xs-4" style="text-align: center;">忘记密码</span>
			<!--<span class="f28 col-xs-4" style="text-align: right;">会员认证</span>-->
		</div>
		<div class="container-fluid">
			<ul>
				<li class="vip_msg_add"> <span>*账号:</span><input style="border: 0;" type="text" name="loginName" id="loginName" value="" placeholder="请输入登录账号" /></li>
				<li class="vip_msg_add"> <span>*手机号码:</span><input style="border: 0;" type="text" name="phone" id="phone" value="" placeholder="请输入手机号码" /></li>
				<li class="vip_msg_add"> <span>*验证码:</span><input style="border: 0;" type="text" name="" id="dongTai" value="" placeholder="请输入验证码" /><button style="background: red;color: white;border: 0;border-radius:1rem ;float: right;margin-right: .2rem;" id="getBtn">免费获取</button></li>
				<li class="vip_msg_add"> <span>*新密码:</span><input style="border: 0;" maxlength="12" type="password" name="" id="pwd" value="" placeholder="请输入新密码" /></li>
				<li class="vip_msg_add"> <span>*确认密码:</span><input style="border: 0;" maxlength="12" type="password" name="" id="repwd" value="" placeholder="请再次输入密码" /></li>
			</ul>

			<p style="position: fixed;bottom: 0;width: 100%;margin: 0;;"><button class="add_btn">确定</button></p>
		</div>
		<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var local = 'http://47.104.13.109/member-service';
			var namestatus = false;
			emailstatus = false;
			$(function() {
				
				var wait = 59;
				
				//验证密码
				$("#repwd").on("blur", function() {
					var pwd = $("#pwd").val(),
						repwd = $("#repwd").val();
					if(repwd != pwd) {
						alert("两次密码不一致!");
						$("#repwd").val("");
					}
				})
				
				//获取验证码
				$("#getBtn").on("click", function() {
						var phone = $("#phone").val();
						var loginName = $("#loginName").val();
						var reg = /^1[0-9]{10}$/;
						console.log(phone);
						var loginNameres = true;
						if(loginName==''){
							loginNameres = false;
						}
						if(reg.test(phone)&&loginNameres) {
							time(this);
							$.ajax({
								type: "GET",
								url: local + '/auth/security/send-sms-code',
								async: false,
								data: {
									'tel': phone,
									'loginName': loginName
								},
								success: function(res) {
									console.log(res);
									$("#getBtn").prop("disabled", 'disabled');
									$("#getBtn").text("请稍等");
									$("#getBtn").css("background", "gray");
								},
								error: function(error) {
									console.log(error);
									var s = JSON.parse(error.responseText);
									alert(s.error_message);
									wait=0;
									$("#getBtn").html("重新发送");
								}
							});
						} else {
							alert("请检查输入的信息!");
						}
					})
				//60s重置验证码

				function time(o) {
					if(wait == 0) {
						o.removeAttribute("disabled");
						o.innerHTML = "重新发送";
						$("#getBtn").css("background", "red");
						wait = 59;
					} else {
						o.setAttribute("disabled", true);
						o.innerHTML = "重新发送(" + wait + ")";
						wait--;
						setTimeout(function() {
							time(o)
						}, 1000)
					}
				}
				
				//验证验证码修改密码
				$(".add_btn").on("click", function() {
					
					var phone = $("#phone").val(),
						dongtai = $("#dongTai").val(),
						pwd = $("#pwd").val(),
						repwd = $("#repwd").val();

					var datas = {
						'newPassword': pwd,
						'rePassword': repwd,
						'passwordType': "login",
						'smsCode': dongtai,
						'tel': phone
					};
					
					if(dongtai && phone) {
						//忘记密码
						$.ajax({
							type: "post",
							url: local + '/auth/security/password',
							async: false,
							data: datas,
							success: function(res) {
								if(res){
									alert("修改密码成功,请使用新密码登录!");
									window.location.href = "../login/login.html";
								}
								console.log(res);
							},
							error: function(error) {
								console.log(error);
								alert(error.responseJSON.error_message);
							}
						});
					} else {
						alert("请补全信息!");
					}
				})

			})
		</script>
	</body>

</html>